package com.capgemini.scaffold.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.capgemini.scaffold.common.Admin;
import com.capgemini.scaffold.common.BusinessException;
import com.capgemini.scaffold.common.ExceptionEnum;
import com.capgemini.scaffold.common.ResponseBean;
import com.capgemini.scaffold.model.ProjectInfo;
import com.capgemini.scaffold.model.ProjectMember;
import com.capgemini.scaffold.model.ProjectSchedule;
import com.capgemini.scaffold.model.User;
import com.capgemini.scaffold.model.request.ProjectQueryReq;
import com.capgemini.scaffold.model.request.ProjectReq;
import com.capgemini.scaffold.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.web.bind.annotation.*;
import com.capgemini.scaffold.common.Admin;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

import static com.capgemini.scaffold.constant.UserConstant.ADMIN_ROLE;
import static com.capgemini.scaffold.constant.UserConstant.USER_LOGIN_STATE;

/**
 * 项目接口
 *
 * @author wjf,lyy
 */
@Api(tags = "项目管理")
@RestController
@RequestMapping("/project")
public class ProjectController {
    @Resource
    private ProjectService projectService;

    @ApiOperation("根据项目名和开始时间查询项目列表")
    @PostMapping("/queryProject")
    public ResponseBean<List<ProjectInfo>> QueryProject(@RequestBody ProjectQueryReq projectQueryReq){
        return ResponseBean.success(projectService.queryProject(projectQueryReq));
    }

    @ApiOperation("新增项目信息")
    @PostMapping("/addProjectInfo")
    public ResponseBean<ProjectReq> AddProjectInfo(@RequestBody ProjectReq projectReq){
        return ResponseBean.success(projectService.addProject(projectReq));
    }

    @ApiOperation("删除项目")
    @DeleteMapping("/deleteProject/{projectId}/{isRole}")
    public ResponseBean<Boolean> DeleteProject(@PathVariable  Integer projectId,@PathVariable Integer isRole){
        if(!Admin.isAdmin(isRole)){
            throw new BusinessException(ExceptionEnum.NO_AUTH,"你没有权限");
        }
        if(projectId <= 0){
            throw new BusinessException(ExceptionEnum.PARAMS_ERROR,"该项目不存在");
        }
        boolean b = projectService.deleteProject(projectId);
        return ResponseBean.success(b);
    }

    @ApiOperation("获取ProjectInfo列表")
    @PostMapping("/getProjectInfo")
    public ResponseBean<ProjectInfo> GetProjectInfo(){
        return ResponseBean.success(projectService.getProjectInfo());
    }

    @ApiOperation("获取ProjectMember列表")
    @PostMapping("/getProjectMember")
    public ResponseBean<ProjectMember> GetProjectMember(){
        return ResponseBean.success(projectService.getProjectMember());
    }


    @ApiOperation("获取ProjectSchedule列表")
    @PostMapping("/getProjectSchedule")
    public ResponseBean<ProjectSchedule> GetProjectSchedule(){
        return ResponseBean.success(projectService.getProjectSchedule());
    }
}
